﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using Zeny.Common.Domain;

namespace Zeny.Common.Dao
{
    /// <summary>
    /// Base class for data access operations.
    /// </summary>
    public abstract class BaseEntityDao<T> : BaseDao
    {
        public T Get(string id)
        {
            return CurrentSession.Get<T>(id);
        }

        public string Insert(T entity)
        {
            return (string)CurrentSession.Save(entity);
        }

        public void Update(T entity)
        {
            CurrentSession.Update(entity);
        }

        public void Delete(T entity)
        {
            CurrentSession.Delete(entity);
        }

        public IList<T> GetAll<T>() where T : class
        {
            ICriteria criteria = CurrentSession.CreateCriteria<T>();
            return criteria.List<T>();
        }
    }
}
